<?php

namespace app\admin\controller;
use app\common\model\OrderList;
use app\admin\controller\Base;
use \think\Request;
use think\facade\View;
use app\common\model\User;
use app\common\model\ProfitMoney;
use app\common\model\ProfitIntegral;
use app\common\model\ProfitScore;
use app\common\model\ProfitOuQi;
use app\common\model\UserRecharge;
use app\common\model\ProfitDraw;
use app\common\model\Order;
use app\common\model\WxpayLog;
class Finance extends Base
{
    /**
     * 消费排行榜
     */
    public function record(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        $whe[] = ['order_type', 'in', [1,2,3,4,11]];
        $whe[] = ['status', '=', 1];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $field = "id,user_id,sum(order_total) as order_total,sum(price) as price,sum(use_money) as use_money,sum(use_integral) as use_integral, sum(use_money) as use_money";
        $list = Order::where($whe)
            ->field($field)
            ->group("user_id")
            ->order("order_total desc")
            ->paginate(['list_rows' => $this->page, 'query' => request()->param()]);
        $page = $list->render();
        $data = [];
        $data['list'] = $list->toArray()['data'];
        $data['count'] = $list->total();
        $data['page'] = $page;
        foreach ($data['list'] as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where('id', '=', $value['user_id'])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        View::assign('user_id', $user_id);
        View::assign('mobile', $mobile);
        View::assign('addtime', $addtime);
           
        return View::fetch("Finance/record");
    }

    /**
     * 余额明细
     */
    public function money_list(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = ProfitMoney::getList($whe, '*', 'id desc', $this->page);
        foreach ($data['list'] as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        
        View::assign('user_id', $user_id);
        View::assign('mobile', $mobile);
        View::assign('addtime', $addtime);

        return View::fetch("Finance/money_list");
    }


    /**
     * 潮币明细
     */
    public function integral_list(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = ProfitIntegral::getList($whe, '*', 'id desc', $this->page);
        foreach ($data['list'] as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        return View::fetch("Finance/integral_list");
    }

    /**
     * 积分明细
     */
    public function score_list(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = ProfitScore::getList($whe, '*', 'id desc', $this->page);
        foreach ($data['list'] as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        
        View::assign('user_id', $user_id);
        View::assign('mobile', $mobile);
        View::assign('addtime', $addtime);
        
        return View::fetch("Finance/score_list");
    }
    
    
    /**
     * 欧气明细
     */
    public function ouqi_list(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = ProfitOuQi::getList($whe, '*', 'id desc', $this->page);
        foreach ($data['list'] as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        
        View::assign('user_id', $user_id);
        View::assign('mobile', $mobile);
        View::assign('addtime', $addtime);

        return View::fetch("Finance/ouqi_list");
    }
     /**
     * 抽奖券明细
     */
    public function draw_list(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $type = trim(input('get.type'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        if ($type) {
            $whe[] = ['type', '=', $type];
        }
        $data = ProfitDraw::getList($whe, '*', 'id desc', $this->page);
        foreach ($data['list'] as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
            $share_info = User::field('nickname,headimg,mobile')->where(['id' => $value['share_uid']])->find();
            if(empty($share_info)){
                $share_info['nickname'] = '';
                $share_info['headimg'] = '';
                $share_info['mobile'] = '';
            }
            $value['share_nickname'] = $share_info['nickname'];
            $value['share_headimg'] = $share_info['headimg'];
            $value['share_mobile'] = $share_info['mobile'];
        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        return View::fetch("Finance/draw_list");
    }

    /**
     * 充值记录
     */
    public function recharge_list()
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $pay_time = trim(input('get.pay_time'));
        $whe = [];
        // $whe[] = ['status', '=', 2];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($pay_time) {
            $time = explode(' - ', $pay_time);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = WxpayLog::getList($whe, '*', 'id desc', $this->page);
        $total_money = 0;
        $total_moneys = WxpayLog::where($whe)->column('content');
        foreach ($total_moneys as $value) {
            $content = json_decode($value,true);
            $total_money += $content['total_fee'] / 100;
        }
        foreach ($data['list'] as &$value) {
            $content = json_decode($value['content'],true);

            $value['money'] = $content['total_fee'] /100;
            
            //  $total_money += $value['money'];
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        
        View::assign('user_id', $user_id);
        View::assign('mobile', $mobile);
        View::assign('pay_time', $pay_time);
        
        View::assign('total_money', $total_money);
        return View::fetch("Finance/recharge_list");
    }
    /**
     *  无限盲盒消费统计
     *created by Admin at 2022/12/30 9:14
     */
    public function infinite_list(){
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $type = trim(input('get.type'));
        $whee = $wheee = [];
        if (empty($type)) {
            $type = 2;
            // $whee[] = ['type', '=', $type];
            // $wheee[] = ['order_type', '=', $type];
        }
        $whee[] = ['type', '=', $type];
        $wheee[] = ['order_type', '=', $type];
        $where = [];
        if ($user_id) {
            $where[] = ['id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $where[] = ['user_id', '=', $mobile];
        }
        $pageSize = 15;
        $list = \app\common\model\Goods::where($whee)->where($where)
            ->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
//        dd($list);field('user_id,sum(goodslist_money) as goods_money,sum(goodslist_price) as goods_price,(sum(goodslist_price) - sum(goodslist_money)) as price,addtime')
        $goods_price_total = 0;
        $goods_money_total = 0;
        $ks_money_total = 0;
        foreach ($list as $value){
            $goods_price = OrderList::where($wheee)
                ->where('goods_id',$value['id'])
                ->field('id')
                ->count('id');
            $goods_money = OrderList::where($wheee)
                ->where('goods_id',$value['id'])
                ->sum('goodslist_money');
            if ($value['type'] == 11) {
                $value['goods_price'] =  Order::where($wheee)->where('goods_id',$value['id'])->sum('order_total');
            } else {
                $value['goods_price'] = $goods_price * $value['price'];
            }   
            $value['goods_money'] = $goods_money;
            $value['ks_money'] = $value['goods_price'] - $goods_money;

            $goods_price_total+= $value['goods_price'];
            $goods_money_total+= $goods_money;
            $ks_money_total+= $value['ks_money'];
        }
        $total_money[1]['goods_price_total'] = $goods_price_total;
        $total_money[1]['goods_money_total'] = $goods_money_total;
        $total_money[1]['ks_money_total'] = $ks_money_total;


//        $list = OrderList::field('user_id,sum(goodslist_money) as goods_money,sum(goodslist_price) as goods_price,(sum(goodslist_price) - sum(goodslist_money)) as price,addtime')
//            ->where($where)
//            ->where('order_type',2)
//            ->group('user_id')
//            ->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
        $page = $list->render();
        $data['list'] = $list->toArray()['data'];
        $data['count'] = $list->total();
        $data['last_page'] = $list->toArray()['last_page'];
        $data['page'] = $page;
//        return $data;
//        foreach ($data['list'] as &$value) {
//            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
//            $value['nickname'] = $user_info['nickname'];
//            $value['headimg'] = $user_info['headimg'];
//            $value['mobile'] = $user_info['mobile'];
//        }
        View::assign('list', $data['list']);
        View::assign('count', $data['count']);
        View::assign('page', $data['page']);
        
        View::assign('type', $type);
        View::assign('total_money', $total_money);
        View::assign('user_id', $user_id);
        
        return View::fetch("Finance/infinite_list");
    }
    
    /**
     * 用户流水导出
     * @$request
     */ 
    public function record_daochu(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        $whe[] = ['order_type', '<', 5];
        $whe[] = ['status', '=', 1];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $field = "id,user_id,sum(order_total) as order_total,sum(price) as price,sum(use_money) as use_money,sum(use_integral) as use_integral, sum(use_money) as use_money";
        $data = Order::where($whe)
            ->field($field)
            ->group("user_id")
            ->order("order_total desc")
            ->select()->toArray();
   
 
        foreach ($data as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where('id', '=', $value['user_id'])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        
        if (!$data) {
            return $this->renderError('未找到数据');
        }

        $save_name = substr(dirname($_SERVER['SCRIPT_FILENAME']), 0, -6);
        require $save_name . 'extend/phpexcel/PHPExcel.php';
        //3.实例化PHPExcel类
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '用户信息')
            ->setCellValue('B1', '总金额')
            ->setCellValue('C1', '微信支付')
            ->setCellValue('D1', '消费余额');
            // ->setCellValue('E1', '余额');
        //设置A列水平居中
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);

        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        // $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A1:M1')->getFont()->setBold(true);

        //设置单元格宽度
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(40);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(50);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
 

        $line = 1;
        foreach ($data as $key => &$value) {
            #订单号
            #用户信息
            $user_info = 'ID：' . $value['user_id'] . "     " . '昵称：' . $value['nickname'] . "     " . '手机号：' . $value['mobile'];
            $line++;
            #开始导出
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, $user_info);#用户信息
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $value['order_total']);#总金额
            $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, $value['price']);#微信支付
            $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, $value['use_money']);#消费余额
            // $objPHPExcel->getActiveSheet()->setCellValue('E' . $line, $value['use_score']);#余额

        }
        //7.设置保存的Excel表格名称
        $filename = '用户流水排行信息' . date('y-m-d H_i_s', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('流水排行信息');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        exit;
    }
    
    
    /**
     * 余额明细
     */
    public function money_list_daochu(Request $request)
    {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if (!empty($addtime)) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = ProfitMoney::where($whe)->order('id desc')->select()->toArray();
        foreach ($data as &$value) {
            $user_info = User::field('nickname,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['mobile'] = $user_info['mobile'];
        }
        if (!$data) {
            return $this->renderError('未找到数据');
        }

        $save_name = substr(dirname($_SERVER['SCRIPT_FILENAME']), 0, -6);
        require $save_name . 'extend/phpexcel/PHPExcel.php';
        //3.实例化PHPExcel类
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '用户信息')
            ->setCellValue('B1', '变化余额数量')
            ->setCellValue('C1', '变后余额数量')
            ->setCellValue('D1', '描述')
            ->setCellValue('E1', '变化时间');
        //设置A列水平居中
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);

        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A1:M1')->getFont()->setBold(true);

        //设置单元格宽度
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(40);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(50);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);

        $line = 1;
        foreach ($data as $key => &$value) {
            #订单号
            #用户信息
            $user_info = 'ID：' . $value['user_id'] . "     " . '昵称：' . $value['nickname'] . "     " . '手机号：' . $value['mobile'];

            $line++;
        
            #开始导出
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, $user_info);#用户信息
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $value['change_money']);#变化余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, $value['money']);#变后余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, $value['content']);#描述
            $objPHPExcel->getActiveSheet()->setCellValue('E' . $line, date('Y-m-d H:i:s', $value['addtime']));#变化时间
        }
        //7.设置保存的Excel表格名称
        $filename = '余额明细信息' . date('y-m-d H_i_s', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('余额明细信息');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        exit;
    }
    
    // 欧气数据导出
    public function ouqi_list_daochu(Request $request) 
    {  
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = ProfitOuQi::where($whe)->order('id desc')->select()->toArray();
        foreach ($data as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        
        if (!$data) {
            return $this->renderError('未找到数据');
        }

        $save_name = substr(dirname($_SERVER['SCRIPT_FILENAME']), 0, -6);
        require $save_name . 'extend/phpexcel/PHPExcel.php';
        //3.实例化PHPExcel类
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '用户信息')
            ->setCellValue('B1', '变化欧气数量')
            ->setCellValue('C1', '变后欧气数量')
            ->setCellValue('D1', '描述')
            ->setCellValue('E1', '变化时间');
        //设置A列水平居中
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);

        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A1:M1')->getFont()->setBold(true);

        //设置单元格宽度
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(40);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(50);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);

        $line = 1;
        foreach ($data as $key => &$value) {
            #订单号
            #用户信息
            $user_info = 'ID：' . $value['user_id'] . "     " . '昵称：' . $value['nickname'] . "     " . '手机号：' . $value['mobile'];

            $line++;
        
            #开始导出
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, $user_info);#用户信息
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $value['change_money']);#变化余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, $value['money']);#变后余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, $value['content']);#描述
            $objPHPExcel->getActiveSheet()->setCellValue('E' . $line, date('Y-m-d H:i:s', $value['addtime']));#变化时间
        }
        //7.设置保存的Excel表格名称
        $filename = '用户欧气明细信息' . date('y-m-d H_i_s', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('欧气明细信息');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        exit;
    }
    
    /**
     * 积分数据导出
     * 
     */ 
     public function score_list_daochu(Request $request)
     {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $addtime = trim(input('get.addtime'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($addtime) {
            $time = explode(' - ', $addtime);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = ProfitScore::where($whe)->order('id desc')->select()->toArray();
        foreach ($data as &$value) {
            $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['headimg'] = $user_info['headimg'];
            $value['mobile'] = $user_info['mobile'];
        }
        if (!$data) {
            return $this->renderError('未找到数据');
        }

        $save_name = substr(dirname($_SERVER['SCRIPT_FILENAME']), 0, -6);
        require $save_name . 'extend/phpexcel/PHPExcel.php';
        //3.实例化PHPExcel类
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '用户信息')
            ->setCellValue('B1', '变化积分数量')
            ->setCellValue('C1', '变后积分数量')
            ->setCellValue('D1', '描述')
            ->setCellValue('E1', '变化时间');
        //设置A列水平居中
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);

        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A1:M1')->getFont()->setBold(true);

        //设置单元格宽度
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(40);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(50);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);

        $line = 1;
        foreach ($data as $key => &$value) {
            #订单号
            #用户信息
            $user_info = 'ID：' . $value['user_id'] . "     " . '昵称：' . $value['nickname'] . "     " . '手机号：' . $value['mobile'];

            $line++;
        
            #开始导出
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, $user_info);#用户信息
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $value['change_money']);#变化余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, $value['money']);#变后余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, $value['content']);#描述
            $objPHPExcel->getActiveSheet()->setCellValue('E' . $line, date('Y-m-d H:i:s',  $value['addtime']));#变化时间
        }
        //7.设置保存的Excel表格名称
        $filename = '用户积分明细信息' . date('y-m-d H_i_s', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('积分明细信息');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        exit;
     }
     
     //微信充值记录明细 
     public function recharge_list_daochu()
     {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $pay_time = trim(input('get.pay_time'));
        $whe = [];
        if ($user_id) {
            $whe[] = ['user_id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $whe[] = ['user_id', '=', $mobile];
        }
        if ($pay_time) {
            $time = explode(' - ', $pay_time);
            $start_time = strtotime($time[0]);
            $end_time = strtotime($time[1]) - 1;
            if ($start_time > $end_time) {
                $this->err('开始时间不能大于结束时间');
            }
            $whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
        }
        $data = WxpayLog::where($whe)->order('id desc')->select()->toArray();
        $total_money = 0;
        foreach ($data as &$value) {
            $content = json_decode($value['content'],true);

            $value['money'] = $content['total_fee'] /100;
            
             $total_money += $value['money'];
            $user_info = User::field('nickname,mobile')->where(['id' => $value['user_id']])->find();
            $value['nickname'] = $user_info['nickname'];
            $value['mobile'] = $user_info['mobile'];
        }
         
        if (!$data) {
            return $this->renderError('未找到数据');
        }

        $save_name = substr(dirname($_SERVER['SCRIPT_FILENAME']), 0, -6);
        require $save_name . 'extend/phpexcel/PHPExcel.php';
        //3.实例化PHPExcel类
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '用户信息')
            ->setCellValue('B1', '订单号')
            ->setCellValue('C1', '充值数量')
            ->setCellValue('D1', '支付时间');
            // ->setCellValue('E1', '变化时间');
        //设置A列水平居中
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);

        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        // $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A1:M1')->getFont()->setBold(true);

        //设置单元格宽度
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(40);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(50);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
        // $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);

        $line = 2;
        foreach ($data as $key => &$value) {
            if ($line == 2) {
                $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, '总计');#用户信息
                $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $total_money);#变化余额数量
                $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, '');#变后余额数量
                $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, '');#变化时间
            }
            #用户信息
            $user_info = 'ID：' . $value['user_id'] . "     " . '昵称：' . $value['nickname'] . "     " . '手机号：' . $value['mobile'];

            $line++;
        
            #开始导出
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, $user_info);#用户信息
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $value['order_no']);#变化余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, $value['money']);#变后余额数量
            // $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, $value['content']);#描述
            $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, date('Y-m-d H:i:s', $value['addtime']));#变化时间
        }
        //7.设置保存的Excel表格名称
        $filename = '微信充值记录信息' . date('y-m-d H_i_s', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('微信充值记录信息');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        exit;
     }
     
     /**
      * 盒子明细导出
      */ 
     public function infinite_list_daochu(Request $request)
     {
        $user_id = trim(input('get.user_id'));
        $mobile = trim(input('get.mobile'));
        $type = trim(input('get.type'));
        $whee = $wheee = [];
        if (empty($type)) {
            $type = 2;
        }
        $whee[] = ['type', '=', $type];
        $wheee[] = ['order_type', '=', $type];
        $where = [];
        if ($user_id) {
            $where[] = ['id', '=', $user_id];
        }
        if ($mobile) {
            $mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
            $where[] = ['user_id', '=', $mobile];
        }
        $pageSize = 15;
        $data = \app\common\model\Goods::where($whee)->where($where)
            ->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
//        dd($data);field('user_id,sum(goodslist_money) as goods_money,sum(goodslist_price) as goods_price,(sum(goodslist_price) - sum(goodslist_money)) as price,addtime')
        $goods_price_total = 0;
        $goods_money_total = 0;
        $ks_money_total = 0;
        foreach ($data as $value){
            $goods_price = OrderList::where($wheee)
                ->where('goods_id',$value['id'])
                ->field('id')
                ->count('id');
            $goods_money = OrderList::where($wheee)
                ->where('goods_id',$value['id'])
                ->sum('goodslist_money');
            $value['goods_price'] = $goods_price * $value['price'];
            $value['goods_money'] = $goods_money;
            $value['ks_money'] = $value['goods_price'] - $goods_money;

            $goods_price_total+= $value['goods_price'];
            $goods_money_total+= $goods_money;
            $ks_money_total+= $value['ks_money'];
        }
        $total_money[1]['goods_price_total'] = $goods_price_total;
        $total_money[1]['goods_money_total'] = $goods_money_total;
        $total_money[1]['ks_money_total'] = $ks_money_total;
         
        if (!$data) {
            return $this->renderError('未找到数据');
        }

        $save_name = substr(dirname($_SERVER['SCRIPT_FILENAME']), 0, -6);
        require $save_name . 'extend/phpexcel/PHPExcel.php';
        //3.实例化PHPExcel类
        $objPHPExcel = new \PHPExcel();
        //4.激活当前的sheet表
        $objPHPExcel->setActiveSheetIndex(0);
        //5.设置表格头（即excel表格的第一行）
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '盒子信息')
            ->setCellValue('B1', '无限池消费金额')
            ->setCellValue('C1', '无限池兑换金额')
            ->setCellValue('D1', '盈亏')
            ->setCellValue('E1', '盒子类型')
            ->setCellValue('F1', '时间');
        //设置A列水平居中
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);

        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:M1')->getAlignment()
            ->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A1:M1')->getFont()->setBold(true);

        //设置单元格宽度
        //6.循环刚取出来的数组，将数据逐一添加到excel表格。
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(40);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(50);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(30);

        $type_arr = ['-','一番赏', '无限赏' ,'擂台赏', '抽卡机', '积分赏', '全局赏', '福利盲盒','领主赏',  '连击赏'];
        $line = 2;
        foreach ($data as $key => &$value) {
            if ($line == 2) {
                $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, '总计');#用户信息
                $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $goods_price_total);#变化余额数量
                $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, $goods_money_total);#变后余额数量
                $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, $ks_money_total);#变化时间
            }
            #盒子信息
            $goods_info = '名称：' . $value['title'] . "     " . '价格：' . $value['price'] ;

            $line++;
        
            #开始导出
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $line, $goods_info);#盒子信息
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $line, $value['goods_price']);#变化余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('C' . $line, $value['goods_money']);#变后余额数量
            $objPHPExcel->getActiveSheet()->setCellValue('D' . $line, $value['ks_money']);#描述
            $objPHPExcel->getActiveSheet()->setCellValue('E' . $line, $type_arr[$value['type']]);#描述
            $objPHPExcel->getActiveSheet()->setCellValue('F' . $line, date('Y-m-d H:i:s',  $value['addtime']));#变化时间
        }
        //7.设置保存的Excel表格名称
        $filename = '盲盒记录信息' . date('y-m-d H_i_s', time()) . '.xls';
        //8.设置当前激活的sheet表格名称；
        $objPHPExcel->getActiveSheet()->setTitle('盲盒充值记录信息');
        //9.设置浏览器窗口下载表格
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="' . $filename . '"');
        //生成excel文件
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //下载文件在浏览器窗口
        $objWriter->save('php://output');
        exit; 
     }
}
